<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>图片</title>
<link rel="stylesheet" type="text/css" href="control.css"/>
<link rel="stylesheet" type="text/css" href="control_main.css" />
<script type="text/javascript">
window.onload = function(){
	searchInfo();
}
function searchInfo(){
	clearUlInner();
	var url = "/networkforum/control/picture_group_control.do";
	
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get(url,function(d){
		var data = toJson(d);
		//page.view('articleInner',article,articleOption);
		page.view("rightUlInner",data.slice(0.15),pictureOption);
		window.parent.iFrameHeight();
		paging.page({
			size:15,
			total:Math.ceil(data.length/15),
			ajaxLoad:false,
			data:data,
			previou:document.getElementById("previouPage"),
			next:document.getElementById("nextPage"),
			current:document.getElementById("currentPage"),
			max:document.getElementById("totalPage"),
			callBack:function(d){
				clearUlInner();
				page.view("rightUlInner",d,pictureOption);
			},
		});
	});
	myajax = null;
}
var pictureOption = {
	userName:{
		param:{id:"userName"},
		style:{color:"blue"}
	},
	pictureGroupName:{
		param:{id:"groupName"},
		bind:{pictureId:"pictureGroupId"},
	},
	pictureNumber:{
		param:{id:"pictureNumber"},
	},
	isPublic:{
		param:{id:"state"},
	}
}
function userHandle(event){
	event = event || window.event;
	var hs = document.getElementById("handleSelect");
	if(!hs){
		hs = document.getElementById("handle").cloneNode(true);
		hs.id = "handleSelect";
	}
	target.parentElement.appendChild(hs);
	var option = {
			'name':{
				'param':{'id':"typeName"}
			}
		};
	var param = {
			'data':[{'name':"美女"},{'name':"性感"}],
			'target':target,
		};
	page.combo("handleSelect",param,option);
}
function createGroup(){
	var ul = document.getElementById("rightUlInner");
	var module = document.getElementById("module");
	var newLi = module.cloneNode(true);
	var handle = newLi.children[newLi.children.length-1];
	handle.onclick = null;
	handle.readOnly="readOnly";
	newLi.style.display = "";
	ul.appendChild(newLi);	
}
function deleteItem(){
	var items = document.getElementsByClassName("checkBox");
	var ul = document.getElementById("rightUlInner");
	var len = items.length;
	var groupIds = new Array();
	for(var i =len-1;i>0;i--){
		var ite = items[i];
		if(ite.checked){
			groupIds.push(ite.parentElement.children[1].pictureId);
			//ul.removeChild(ite.parentElement);
		}	
	}
	if(groupIds.length==0)return;
	
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/pictureGroup/delete_group.do?groupIds="+groupIds,function(d){
		location.reload();
	});
	myajax = null;
}
function save(){
	var items = document.getElementsByClassName("checkBox");
	
	var len = items.length;
	var groupNames = new Array();
	var groupIds = new Array();
	var states = new Array();
	for(var i =0;i<len ;i++){
		var ite = items[i];
		if(ite.checked){
			var li = ite.parentElement;
			var name = li.children[1].value;
			var pictureId = li.children[1].pictureId||0;
			var len = li.children.length;
			var temp = li.children[5].value;
			if(temp==" "){
				temp = li.children[4].innerHTML;
			}
			var state = (temp=="发布"||temp=="true")?true:false;
			groupNames.push(encodeURIComponent(name));
			groupIds.push(pictureId);
			states.push(state);
		}
	}
	if(groupNames.length==0){
		return;
	}
	var url = "/networkforum/control/picture_group_change.do";
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get(url+"?groupNames="+groupNames+
			"&groupIds="+groupIds+"&states="+states,function(d){
		searchInfo();
	});
	myajax = null;
}
function groupHandle(event){
	event = event || window.event;
	var target = event.target || event.srcElement;
	var hs = document.getElementById("handleSelect");
	if(!hs){
		hs = document.getElementById("handle").cloneNode(true);
		hs.id = "handleSelect";
	}
	target.parentElement.appendChild(hs);
	var option = {
			'name':{
				'param':{'id':"typeName"},
			}
		};
	var param = {
			'data':[{'name':"发布"},{'name':"禁用"}],
			//'data':pg,
			'target':target,
		};
	page.combo("handleSelect",param,option);
}
</script>
</head>

<body>
    <div id="rightNav">
        <span onclick="createGroup();" style="display:inline-block;padding:3px 30px;border-radius:5px;border:1px solid #ccc;margin-top:3px;cursor:pointer;">新增</span>
        <span onclick="deleteItem();" style="display:inline-block;padding:3px 30px;border-radius:5px;border:1px solid #ccc;margin-top:3px;cursor:pointer;">删除</span>
    </div>
    <div id="userCenter" class="rightCenter">
        <ul id="rightUlInner" class="rightUlInner">
            <li id="module" style="display:none;">
                <input class="checkBox" type="checkbox" style="width:5%;margin-right:4px;"/>
                <input id="groupName" value=" " type="text" style="width:50%;text-align:left;"/>
                <span id="pictureNumber" style="width:10%;"></span>
                <span id="userName" style="width:15%;"></span> 
                <span id="state" style="width:5%;"></span>
                <input style="width:5%;" id="wallState" onclick="groupHandle(event);" value=" "></span>
            </li>
            <li id="header">
                <span style="width:5%;">全部</span>
                <span style="width:50%;text-align:left;">组名</span>
                <span style="width:10%;">图片数量</span>
                <span style="width:15%;">创建人员</span>
                <span style="width:5%;">发布</span>
            </li>
        </ul>
	     <div class="paging" id="paging">
	   		<div class="clear"></div>
	   		<span id="previouPage" style="cursor: pointer;">上一页</span>
	   		<!--  <span id="currentPage2">1</span>-->
	   		<input id="currentPage" type="text" value = "1"/>	
	   		<span id="nextPage" style="cursor: pointer;">下一页</span>
	   		<span id="totalPage">共 1 页</span>
	   	</div>
       <ul id="handle" style="display:none;">
            <li>
           		<span id="typeName"></span>
        	</li>
        </ul>
     </div>
     <span onclick="save();" style="display:inline-block;padding:3px 30px;border-radius:5px;border:1px solid #ccc;margin-top:5px;cursor:pointer;">保存</span>
</body>
<script type="text/javascript" src="control_main.js"></script>
<script src="../js/view.js" type="text/javascript"></script>
<script src="../js/combo.js" type="text/javascript"></script>
<script src="../js/myajax.js" type="text/javascript"></script>
<script src="../js/pageing.js" type="text/javascript"></script>
</html>
